<?php

namespace Modules\Ui\component;

use Modules\Ui\Traits\Makenable;
use function PHPUnit\Framework\callback;

class Layout extends Content
{
    use Makenable;

    /**
     * @param callable $callback
     */
    public function __construct(callable $callback)
    {
       return call_user_func($callback,$this);
    }

    /**
     * 设置 PageHeader
     * @param string $title 标题
     * @param string $subtitle 副标题
     * @param bool $back 是否显示返回按钮
     * @param string $extra 右侧区块内容
     * @return $this
     */
    public function pageHeader(string $title = '',string $subtitle = '',bool $back = false, string $extra = ""): Layout
    {
        $this->assign("pageHeader",[
            'title'=>$title,
            'subtitle'=>$subtitle,
            'showBack'=>$back,
            'extra'=>$extra,
        ]);
        $this->addScript(<<<JS
const onPageHeaderBack = ()=>{
    window.dux.router.router.back()
}
JS,'onPageHeaderBack');
        return $this;
    }

    /**
     * 设置 PageHeader
     * @param callable|string $handleOk 提交
     * @param callable|string $handleOClose 关闭
     * @return $this
     */
    public function modal(array $options, $handleOk = "()=>onModalVisibleToggle()",  $handleOClose = "()=>onModalVisibleToggle()"): Layout
    {
        $this->assign("modalValue",$options);
        $this->addVariable("visible",'ref(false)');
        $this->addVariable("isFullscreen",'ref(false)');
        $this->addVariable("onModalVisibleToggle","()=>{console.log(visible);visible.value = !unref(visible)}");
        $this->addVariable("onModalHandleOk",is_callable($handleOk)?call_user_func($handleOk,$this):$handleOk);
        $this->addVariable("onModalHandleClose",is_callable($handleOClose)?call_user_func($handleOClose,$this):$handleOClose);
        return $this;
    }

    public function toArray(){

    }
}
